package com.huawei.appgallery.horizontalcard.api.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.Interpolator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import o.cjy;
import o.cjy.d;
import o.cll;
import o.MinimumFactory;

@SuppressLint({"ClickableViewAccessibility"})
public class BounceHorizontalRecyclerView extends RecyclerView implements d {
    protected cjy ˏˏ = null;
    protected boolean ͺॱ = false;
    private float ـ = 0.0f;
    private boolean ॱʻ = false;
    private b ॱʼ;
    private Interpolator ॱʽ;
    private float ॱͺ = 0.0f;
    private boolean ᐝˊ = false;
    private int ᐝˋ;
    private c ᐝᐝ;
    private boolean ᐧ = false;
    private boolean ᐨ = false;
    private int ꓸ = 1;

    public interface b {
        void ˊ();
    }

    public interface c {
        boolean ˏ();
    }

    static class e implements Interpolator {
        private e() {
        }

        public float getInterpolation(float f) {
            return (float) (1.0d - Math.pow((double) Math.abs(f - 1.0f), 2.0d));
        }
    }

    public BounceHorizontalRecyclerView(Context context) {
        super(context);
        ˊ(null);
        ˏˎ();
    }

    public BounceHorizontalRecyclerView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˊ(attributeSet);
        ˏˎ();
    }

    public BounceHorizontalRecyclerView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˊ(attributeSet);
        ˏˎ();
    }

    public void setTouchListener(b bVar) {
        this.ॱʼ = bVar;
    }

    private void ˏˎ() {
        this.ॱʽ = new e();
    }

    public void ˊ(int i, int i2) {
        super.ˊ(i, i2, this.ॱʽ);
    }

    private void ˊ(AttributeSet attributeSet) {
        if (attributeSet != null) {
            TypedArray typedArray = null;
            try {
                typedArray = getContext().obtainStyledAttributes(attributeSet, o.clo.e.ॱᐨ);
                this.ͺॱ = typedArray.getBoolean(o.clo.e.ॱᐧ, false);
                if (typedArray != null) {
                    typedArray.recycle();
                }
            } catch (RuntimeException e) {
                cll.ˎ.ˊ("BounceHorizontalRecyclerView", "init(AttributeSet attrs) " + e.toString());
                if (typedArray != null) {
                    typedArray.recycle();
                }
            } catch (Throwable th) {
                if (typedArray != null) {
                    typedArray.recycle();
                }
            }
        }
        if (this.ͺॱ) {
            this.ˏˏ = new cjy(this);
        }
    }

    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        switch (motionEvent.getAction()) {
            case 0:
                this.ـ = motionEvent.getY();
                this.ॱͺ = motionEvent.getX();
                this.ᐝˊ = true;
                break;
            case 2:
                if (!this.ᐧ || !ˊ(motionEvent)) {
                    if (ॱ(motionEvent) < ˋ(motionEvent)) {
                        this.ॱʻ = false;
                        if (getParent() != null) {
                            getParent().requestDisallowInterceptTouchEvent(false);
                            break;
                        }
                    }
                    if (getParent() != null) {
                        getParent().requestDisallowInterceptTouchEvent(true);
                    }
                    this.ॱʻ = true;
                    return super.dispatchTouchEvent(motionEvent);
                }
                this.ـ = motionEvent.getY();
                this.ॱͺ = motionEvent.getX();
                this.ॱʻ = false;
                if (getParent() != null) {
                    getParent().requestDisallowInterceptTouchEvent(false);
                }
                return super.dispatchTouchEvent(motionEvent);
                break;
        }
        return super.dispatchTouchEvent(motionEvent);
    }

    private boolean ˊ(MotionEvent motionEvent) {
        if ((!MinimumFactory.getBoolValue(getContext()) || motionEvent.getX() - this.ॱͺ <= 0.0f || !ˌ()) && (MinimumFactory.getBoolValue(getContext()) || motionEvent.getX() - this.ॱͺ >= 0.0f || !ˋˋ())) {
            return false;
        }
        return true;
    }

    public int ˋ(MotionEvent motionEvent) {
        return Math.abs((int) (motionEvent.getY() - this.ـ));
    }

    public int ॱ(MotionEvent motionEvent) {
        return Math.abs((int) (motionEvent.getX() - this.ॱͺ));
    }

    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        if (this.ॱʻ && getParent() != null) {
            getParent().requestDisallowInterceptTouchEvent(true);
        }
        if (this.ͺॱ && this.ˏˏ != null) {
            this.ˏˏ.ˋ(motionEvent);
        }
        try {
            return super.onInterceptTouchEvent(motionEvent);
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.ॱʻ && getParent() != null) {
            getParent().requestDisallowInterceptTouchEvent(true);
        }
        try {
            if (motionEvent.getAction() == 1 && this.ॱʼ != null) {
                this.ॱʼ.ˊ();
            }
            if (this.ͺॱ && this.ˏˏ != null && this.ˏˏ.ˏ(motionEvent)) {
                return true;
            }
            return super.onTouchEvent(motionEvent);
        } catch (IllegalArgumentException e) {
            cll.ˎ.ˊ("BounceHorizontalRecyclerView", "onTouchEvent(MotionEvent ev)  " + e.toString());
            return false;
        }
    }

    public boolean ˌ() {
        return !canScrollHorizontally(-1);
    }

    public boolean ˋˋ() {
        return !canScrollHorizontally(1);
    }

    public boolean ˎˎ() {
        return false;
    }

    public boolean ˋᐝ() {
        return false;
    }

    public void ʼ(int i) {
        int ˌ = ʻ().ˌ();
        if (ʻ() instanceof LinearLayoutManager) {
            this.ᐝˋ = ((LinearLayoutManager) ʻ()).ʻॱ();
        }
        if (this.ᐝˊ && !this.ᐨ && this.ᐝˋ >= ˌ - this.ꓸ && this.ᐝᐝ != null) {
            this.ᐝˊ = false;
            if (this.ᐝᐝ.ˏ()) {
                this.ᐨ = true;
            }
        }
    }

    public void setStartLoadNum(int i) {
        this.ꓸ = i;
    }

    public void setOnLoadListener(c cVar) {
        this.ᐝᐝ = cVar;
    }

    public boolean ˑ() {
        return this.ᐨ;
    }

    public void setLoading(boolean z) {
        this.ᐨ = z;
    }

    public void setUnInterceptOnRight(boolean z) {
        this.ᐧ = z;
    }
}
